from php4dvd.pages.page import Page
from selenium.webdriver.common.by import By


class IMDBResultsPage(Page):

    @property
    def logout_button(self):
        return self.driver.find_element_by_css_selector("nav a[href $= '?logout']")

    @property
    def user_profile_link(self):
        return self.driver.find_element_by_css_selector("nav a[href $= '?go=profile']")

    @property
    def user_management_link(self):
        return self.driver.find_element_by_css_selector("nav a[href $= '?go=users']")

    @property
    def is_this_page(self):
        return self.is_element_visible((By.CSS_SELECTOR, "table.imdbmovies.hover"))

    @property
    def results_table(self):
        return self.driver.find_element_by_css_selector("table.imdbmovies.hover")

    def result_click(self,do_tr = "1", do_td = "2"):
        temp = self.wait.until(lambda x: self.is_element_visible((By.XPATH, "//table/tbody/tr["+do_tr+"]/td["+do_td+"]/a")))
        if temp:
            cell = self.results_table.find_element_by_xpath("//table/tbody/tr["+do_tr+"]/td["+do_td+"]/a")
            cell.click()
        #table = self.driver.find_element_by_css_selector("table.imdbmovies.hover").find_elements_by_tag_name("tr")[do_tr].find_elements_by_tag_name("td")[do_td]
        #table.click
        #return 1


